package com.zcx.qshop.action;

import com.zcx.helper.util.UtilToast;
import com.zcx.qshop.activity.CompleteOrderActivity;

import android.content.Context;
import android.widget.Toast;

import java.util.HashMap;

import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.PlatformActionListener;
import cn.sharesdk.framework.ShareSDK;
import cn.sharesdk.tencent.qq.QQ;
import cn.sharesdk.tencent.qzone.QZone;
import cn.sharesdk.wechat.friends.Wechat;

public class ShareAction {

	private Context context;

	private PlatformActionListener platformActionListener = new PlatformActionListener() {

		@Override
		public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

					Toast.makeText(context, "分享成功.", Toast.LENGTH_SHORT).show();

					if(CompleteOrderActivity.onShareSuccessListener != null){

						CompleteOrderActivity.onShareSuccessListener.onShareSuccess();

					}

		}

		@Override
		public void onError(Platform platform, int i, Throwable throwable) {}

		@Override
		public void onCancel(Platform platform, int i) {}

	};

    public ShareAction(Context context){

        ShareSDK.initSDK(this.context = context, "cde80c1a9f14");

    }

	public void shareQQ(final Context context) {

		QQ.ShareParams shareParams = new QQ.ShareParams();

		shareParams.setTitle("测试分享的标题");

		shareParams.setTitleUrl("http://sharesdk.cn");

		shareParams.setText("测试分享的文本");

		shareParams.setImageUrl("http://www.someserver.com/测试图片网络地址.jpg");

		shareParams.setSite("发布分享的网站名称");

		shareParams.setSiteUrl("发布分享网站的地址");

		Platform platform = ShareSDK.getPlatform (QQ.NAME);

		platform.setPlatformActionListener(new PlatformActionListener() {

			@Override
			public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

				UtilToast.show(context, "onComplete");

			}

			@Override
			public void onError(Platform platform, int i, Throwable throwable) {

				UtilToast.show(context, "onError");

			}

			@Override
			public void onCancel(Platform platform, int i) {

				UtilToast.show(context, "onCancel");

			}

		});

		platform.share(shareParams);

	}

	public void shareQzone(final Context context){

		QZone.ShareParams shareParams = new QZone.ShareParams();

		shareParams.setTitle("测试分享的标题");

		shareParams.setTitleUrl("http://sharesdk.cn");

		shareParams.setText("测试分享的文本");

		shareParams.setImageUrl("http://www.someserver.com/测试图片网络地址.jpg");

		shareParams.setSite("发布分享的网站名称");

		shareParams.setSiteUrl("发布分享网站的地址");

		Platform platform = ShareSDK.getPlatform (QZone.NAME);

		platform.setPlatformActionListener(new PlatformActionListener() {

			@Override
			public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

				UtilToast.show(context, "onComplete");

			}

			@Override
			public void onError(Platform platform, int i, Throwable throwable) {

				UtilToast.show(context, "onError");

			}

			@Override
			public void onCancel(Platform platform, int i) {

				UtilToast.show(context, "onCancel");

			}

		});

		platform.share(shareParams);

	}

	public void shareWX(final Context context){

		Wechat.ShareParams shareParams = new Wechat.ShareParams();

		shareParams.setTitle("测试分享的标题");

		shareParams.setTitleUrl("http://sharesdk.cn");

		shareParams.setText("测试分享的文本");

		shareParams.setImageUrl("http://www.someserver.com/测试图片网络地址.jpg");

		shareParams.setSite("发布分享的网站名称");

		shareParams.setSiteUrl("发布分享网站的地址");

		Platform platform = ShareSDK.getPlatform (Wechat.NAME);

		platform.setPlatformActionListener(new PlatformActionListener() {

			@Override
			public void onComplete(Platform platform, int i, HashMap<String, Object> hashMap) {

				UtilToast.show(context, "onComplete");

			}

			@Override
			public void onError(Platform platform, int i, Throwable throwable) {

			}

			@Override
			public void onCancel(Platform platform, int i) {

			}

		});

		platform.share(shareParams);

	}

	public void shareWXF(final Context context){

//		String appID = "wx66bd71b8aa0cb688";
//
//		String appSecret = "9196468d0821a659e0b10abc68652bd0";
//
//		UMWXHandler wxCircleHandler = new UMWXHandler(context, appID, appSecret);
//
//		wxCircleHandler.setToCircle(true);
//
//		wxCircleHandler.addToSocialSDK();
//
//		CircleShareContent circleMedia = new CircleShareContent();
//
//		circleMedia.setTitle("易城");
//
//		circleMedia.setShareImage(new UMImage(context, R.mipmap.icon));
//
//		circleMedia.setTargetUrl(Conn.SERVICE + "share/index.php");
//
//		circleMedia.setShareContent("让生活变得更轻松！");
//
//		controller.setShareMedia(circleMedia);
//
//		controller.postShare(context, SHARE_MEDIA.WEIXIN_CIRCLE, new SnsPostListener() {
//
//			@Override
//			public void onStart() {
//
//				Toast.makeText(context, "开始分享.", Toast.LENGTH_SHORT).show();
//
//			}
//
//			@Override
//			public void onComplete(SHARE_MEDIA platform, int eCode, SocializeEntity entity) {
//
//				if (eCode == StatusCode.ST_CODE_SUCCESSED) {
//
//					Toast.makeText(context, "分享成功.", Toast.LENGTH_SHORT).show();
//
//					if(CompleteOrderActivity.onShareSuccessListener != null){
//
//						CompleteOrderActivity.onShareSuccessListener.onShareSuccess();
//
//					}
//
//				} else {
//
//					String eMsg = "";
//
//					if (eCode == -101) {
//
//						eMsg = "没有授权";
//
//					}
//
//					Toast.makeText(context, "分享失败[" + eCode + "] " + eMsg, Toast.LENGTH_SHORT).show();
//
//				}
//
//			}
//
//		});

	}

}
